﻿@model IEnumerable<zyzyzy1.Models.Defect>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<form mothod="get" class="form-inline text-center" style="margin:10px">
    所属设备:@Html.DropDownList("DeviceID", null, new { @class = "form-control" })
    缺陷内容:<input type="text" name="Content" class="form-control" placeholder="请输入关键字" />
    缺陷状态:<input type="radio" id="rl" name="DefectState" value="1" /><label for="rl">紧急</label>
    <input type="radio" id="r2" name="DefectState" value="2" /><label for="r2">重要</label>
    <input type="radio" id="r3" name="DefectState" value="0" checked="checked"/><label for="r3">一般</label>
    <input type="submit" value="查询" class="btn-primary" />
    @Html.ActionLink("添加", "Create", null, new { @class = "btn btn-primary" })

</form>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.DefectType)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Content)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DefectState)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DealTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DeviceID)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @if (item.DefectType == 1)
            {
                @:紧急
            }
            else if (item.DefectType == 2)
            {
                @:重要
            }
            else if (item.DefectType == 3)
            {
                @:一般
            }
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Content)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.AddTime)
        </td>
        <td>
            @(item.DefectState==1?"未处理":"已处理")
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.DealTime)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.DeviceID)
        </td>
        <td class="text-right">
            @if (item.DefectState == 1)
            {
                <a href="#" class="btn btn-primary" data-edit="@item.DefectID">处理缺陷</a>
            }
            <a href="#" class="btn btn-danger" data-del="@item.DefectID">删除</a>
        </td>
    </tr>
}

</table>
@section scripts{
    <script type="text/javascript">
        $(function () {
            $("a[data-del]").click(function () {
                var $this = $(this);
                var id = $this.attr("data-del");
                if (!confirm("你确定要删除ID=" + id + "?")) return;
                $.post("@Url.Content("~/Default/Delete")", { id: id }, function (res) {
                    if (res == true) {
                        alert("删除成功");
                        location.reload();
                    }
                })
            })


            $("a[data-edit]").click(function () {
                var $this = $(this);
                var id = $this.attr("data-edit");
                $.post("@Url.Content("~/Default/Edit")", { id: id }, function (res) {
                    if (res == true) {
                        alert("处理缺陷成功");
                        location.reload();
                    }
                })
            })
        })
    </script>
    
    
    }
